﻿using System.ComponentModel.DataAnnotations;

namespace Shop.Core.Share
{
    /// <summary>
    /// 分页查询对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PageSearchModel<T> : IPageSearchModel
    {
        /// <summary>
        /// 当前页码
        /// </summary>
        private int _pageIndex = 1;

        /// <summary>
        /// 
        /// </summary>
        private int _pageSize = 20;

        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex
        {
            get
            {
                return _pageIndex < 1 ? 1 : _pageIndex;
            }
            set
            {
                _pageIndex = value;
            }
        }

        /// <summary>
        /// 每页显示条数
        /// </summary>
        public int PageSize
        {
            get
            {
                if (_pageSize < 5) _pageSize = 5;
                if (_pageSize > 100) _pageSize = 100;
                return _pageSize;
            }
            set
            {
                _pageSize = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        [Required]
        public T Value { get; set; }
    }

    /// <summary>
    /// 分页查询对象
    /// </summary>
    public class PageSearchModel : IPageSearchModel
    {
        private int _pageIndex;
        private int _pageSize;

        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex
        {
            get
            {
                return _pageIndex < 1 ? 1 : _pageIndex;
            }
            set
            {
                _pageIndex = value;
            }
        }

        /// <summary>
        /// 每页显示条数
        /// </summary>
        public int PageSize
        {
            get
            {
                if (_pageSize < 5) _pageSize = 5;
                if (_pageSize > 100) _pageSize = 100;
                return _pageSize;
            }
            set
            {
                _pageSize = value;
            }
        }
    }
}
